import { Controller } from "egg";
import * as path from "path";
import * as fs from 'fs';

export default class HomeController extends Controller {
  public async index() {
    const { ctx,app} = this;
    // await ctx.render("index");
    // console.log(ctx.request.files);
    // ctx.getFileStream();
     const stream = await ctx.getFileStream({
       defCharset:'utf8'
     });
    //  const name = "egg-multipart-test/" + path.basename(stream.filename);
   
    stream.pipe(
      fs.createWriteStream(path.join(app.baseDir, "asset", stream.filename), {
        encoding: "utf8",
      })
    );
    ctx.body = stream.filename;
  }

}
